<div class="step">
	第1步<i>&gt;</i>第2步<i>&gt;</i><span class="cur">第3步</span><i>&gt;</i>第4步<i>&gt;</i>第5步
</div>

<form action="setup.php" method="post">

	<table class="tb right">
		<caption>数据库配置</caption>
		<tbody class="db">
			<!-- <tr>
				<th style="width:190px;">驱动</th>
				<td style="width:240px;">
					<input type="radio" name="driver" value="mysqli" checked />
					MySQLi
					<input type="radio" name="driver" value="pdo" />
					PDO</td>
				<td></td>
			</tr> -->
			<tr>
				<th style="width:190px;">主机</th>
				<td style="width:240px;"><input type="text" name="db_host" value="localhost" class="input" style="width:240px;" /></td>
				<td></td>
			</tr>
			<tr>
				<th>用户名</th>
				<td><input type="text" name="db_user" value="root" class="input" style="width:240px;" /></td>
				<td></td>
			</tr>
			<tr>
				<th>密码</th>
				<td><input type="password" name="db_pass" value="" class="input" style="width:240px;" /></td>
				<td></td>
			</tr>
			<tr>
				<th>数据库名</th>
				<td><input type="text" name="db_name" value="dxe_shop" class="input" style="width:240px;" /></td>
				<td id="re"></td>
			</tr>
			<tr id="way">
				<th>安装方式</th>
				<td><label><input type="radio" name="way" value="0" checked />
						默认（全新安装）<br /></label>
					<label><input type="radio" name="way" value="1" />
						跳过数据表<br /></label>
					<label><input type="radio" name="way" value="2" />
						<span class="red">强制安装（会清除原有数据）</span></td></label>
				<td></td>
			</tr>
			<tr>
				<th>表名前缀</th>
				<td><input type="text" name="db_pre" value="tb_" class="input" style="width:240px;" /></td>
				<td></td>
			</tr>
			<!-- <tr>
				<th>示例数据</th>
				<td><input type="checkbox" name="demo" value="1" checked class="chbox" />
					助您快速熟悉系统</td>
				<td>安装完成后，请确认目录/data/uploads/下存在示例文件，才能完整体验</td>
			</tr> -->
			
		</tbody>
	</table>

	<div class="btn_area">
		<input type="button" value="检测" class="button" onclick="javascript:check_db();return false;" />
	</div>

	<table class="tb right">
		<caption>网站标识</caption>
		<tbody>
			<tr>
				<th style="width:190px;">安全码</th>
				<td style="width:240px;"><input type="text" name="sitekey" value="{$sitekey}" class="input" style="width:240px;" /></td>
				<td></td>
			</tr>
			<tr>
				<th>前缀</th>
				<td><input type="text" name="pre" value="{$pre}" class="input" style="width:240px;" /></td>
				<td>主要用于Cookie，用于区分不同站点</td>
			</tr>
		</tbody>
	</table>

	<table class="tb right">
		<caption>管理员配置</caption>
		<tbody>
			<tr>
				<th style="width:190px;">管理员帐号</th>
				<td style="width:240px;"><input type="text" name="m_user" value="admin" class="input" style="width:240px;" /></td>
				<td></td>
			</tr>
			<tr>
				<th>管理员密码</th>
				<td><input type="password" name="m_pass" value="" class="input" style="width:240px;" /></td>
				<td></td>
			</tr>
			<tr>
				<th>确认密码</th>
				<td><input type="password" name="m_pwd" value="" class="input" style="width:240px;" /></td>
				<td></td>
			</tr>
			<tr>
				<th>管理员邮箱</th>
				<td><input type="text" name="m_email" value="" class="input" style="width:240px;" /></td>
				<td></td>
			</tr>
		</tbody>
	</table>

	<div class="btn_area">
		<input type="button" value="上一步" class="button" onclick="javascript:history.back(-1);return false;" />
		<input type="submit" value="下一步" class="button" />
	</div>
</form>

<script type="text/javascript" language="javascript" charset="utf=8">
<!--
	var data = {'check' : 1};
	var list = ['driver', 'db_host', 'db_user', 'db_pass', 'db_name', 'db_pre'];
	var db_status = false;
	jQuery(function($){
		$('.db').find('input[type="text"]').change(check_db);

		$('form').submit(function(){
			var fieldlist = ['db_host', 'db_user', /*'db_pass',*/ 'db_name', 'db_pre', 'm_user', 'm_pass', 'm_pwd', 'm_email'];
			var field = '', input = null, title = '';
			var checked = true;
			var way = $('input[name="way"]:checked').val();
			if(way == '0'){	// 默认情况下，需要数据库检测OK才能通过
				checked = db_status;
			}
			for(var x in fieldlist){
				field = fieldlist[x];
				input = $('input[name="'+field+'"]');
				value = $.trim(input.val());
				if(value == ''){
					checked = false;
					title = input.parents('tr').find('th').text();
					input.parents('tr').find('td:last').text('未输入'+title).attr('class', 'red');
				}else{
					if(field != 'db_name'){
						input.parents('tr').find('td:last').text('');
					}
				}
			}
			if(checked == true){
				if($('input[name="m_pwd"]').val() != $('input[name="m_pass"]').val()){
					$('input[name="m_pwd"]').parents('tr').find('td:last').text('两次输入的密码不一致').attr('class', 'red');
					checked = false;
				}
			}
			if(db_status == false){
				check_db();
			}
			return checked;
		});

	});

	function check_db(){
		var field = '';
		for(var x in list){
			field = list[x];
			data[field] = jQuery.trim(jQuery('.db').find('input[name="'+field+'"]').val());
		}
		jQuery.post(
			'./input.php',
			data,
			function(re){
				if(re == 'ok'){
					db_status = true;
					$('#re').attr('class', 'green').html(re);
				}else{
					db_status = false;
					$('#re').attr('class', 'red').html(re);
				}
			}
		);
	}
//-->
</script>